# -*- encoding=utf8 -*-
__author__ = "v_jwjwchen"
import sys,os
sys.path.append(os.getcwd())
from auto_delivery_config import *
from airtest.core.api import *
def init_idle_fish(package_name):
    '''初始化app'''
    stop_app(package_name)
    sleep(5)
    start_app(package_name)
    
def wait_for_appearance_and_click(object):
    '''等待元素出现并点击'''
    object.wait_for_appearance()
    print ("找到位置,准备点击")
    object.click()
    print ("已点击")
    
def click_element_list(object_list,click_max_times,direction="asc"):
    '''
    指定次数点击元素列表中的元素
    :object_list:被匹配的poco元素对象列表
    :click_max_times:最多点击次数
    '''
    a=0
    count = len(object_list)
    if direction == "desc": #反向选择
        for i in range(count):
            j=abs(i-count+1)
            object_list[j].click()
            a+=1
            if a == click_max_times:
                break
    elif direction == "asc":#正向选择
        for i in range(count):
            object_list[i].click()
            a+=1
            if a == click_max_times:
                break
     
def choice_comment():
    '''自动随机选择内容'''
    from random import choice
    comment_list = []
    for i in range(1,30):
        comment_num='comment'+'_%s'%i
        try:
            comment = globals()[comment_num]
        except:
            comment = None
        if comment:
            comment_list.append(comment)
    comment = choice(comment_list) 
    return comment

def if_exists_try_click(object,attempts=3):
    if object.exists():
        print ("页面存在,准备点击")
        object.click()
        
    


if __name__ == "__main__":
    print (choice_comment())